<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1">
    <title>测试文档</title>
    <!--引入css-->
    <link rel="stylesheet" href="../css/reset.css" />
    <link rel="stylesheet" href="../css/public.css" />
    <script type="text/javascript">
        if (/Android (\d+\.\d+)/.test(navigator.userAgent)) {
            var version = parseFloat(RegExp.$1);
            if (version > 2.3) {
                var phoneScale = parseInt(window.screen.width) / 750;
                document.write('<meta name="viewport" content="width=750, minimum-scale = ' + phoneScale +
                    ', maximum-scale = ' + phoneScale + ', target-densitydpi=device-dpi">');
            } else {
                document.write('<meta name="viewport" content="width=750, target-densitydpi=device-dpi">');
            }
        } else {
            document.write('<meta name="viewport" content="width=750, user-scalable=no">');
        }
    </script>
    <style>
        .list-box {
            position: fixed;
            right: 0;
            bottom: 0;
            left: 0;
            z-index: 999;
            background: #fff;
        }

        .list {
            height: 362px;
            overflow-y: auto;
        }

        .list li {
            height: 64px;
            text-align: center;
            font-size: 36px;
            line-height: 64px;
        }

        .list li:first-child {
            padding-top: 149px;
        }

        .list li:last-child {
            padding-bottom: 149px;
        }

        .line {
            position: absolute;
            top: 149px;
            display: block;
            width: 100%;
            height: 63px;
            background: transparent;
            border-top: 1px solid #ccc;
            border-bottom: 1px solid #ccc;
        }
    </style>
</head>

<body class="bg-fafafc">
    <div>
        <p id="numVal"></p>
    </div>
    <div class="mask"></div>
    <div class="list-box">
        <ul id="list" class="list">
            <li>1</li>
            <li>2</li>
            <li>3</li>
            <li>4</li>
            <li>5</li>
            <li>6</li>
            <li>7</li>
            <li>8</li>
            <li>9</li>
            <li>10</li>
            <li>11</li>
            <li>12</li>
            <li>13</li>
            <li>14</li>
            <li>15</li>
            <li>16</li>
            <li>17</li>
            <li>18</li>
            <li>19</li>
            <li>20</li>
        </ul>
        <span class="line"></span>
    </div>
    <script type="text/javascript" src="../js/jquery-1.8.3.min.js"></script>
    <script type="text/javascript" src="../js/scroll.js"></script>

    <script>
        function scrollTest() {
            // 滑动的距离
            var $list = document.getElementById("list");
            var $li = $(".list").find("li");
            var liH = $li.height(); // li的高度
            var num = $li.length; //li标签的长度
            var Y = $($list).offset().left;
            var scrollTopH = $list.scrollTop; //滑动的长度
            var remainder = scrollTopH % liH; //滑动距离是否在中间
            var num_test = Math.floor(scrollTopH / liH);
            if (remainder >= liH / 2) {
                // $(".list").unbind('scrollstop');
                // $list.scrollTo(Y, (num_test + 1) * liH);
                $($list).animate({"scrollTop": (num_test + 1) * liH}, 100);
                // setTimeout(function () {
                //     $(".list").bind('scrollstop', scrollTest);
                // }, 150);

            } else {
                // $(".list").unbind('scrollstop');
                // $list.scrollTo(Y, num_test  * liH);
                $($list).animate({"scrollTop": (num_test) * liH}, 100);
                // setTimeout(function () {
                //     $(".list").bind('touchend', scrollTest);
                // }, 150);
            }
        }

        (function () {
            // $(".list").bind('touchend', function(){
            //     scrollTest();
            // });

            $(".list").bind('touchmove', function(){
                scrollTest();
            });


        })();
    </script>
</body>

</html>